package com.bxl.netty.rpc.register.server.service.impl;


import com.bxl.netty.rpc.client.common.client.AppInfo;
import com.bxl.netty.rpc.client.common.client.ClientInfo;
import com.bxl.netty.rpc.common.message.BaseResponse;
import com.bxl.netty.rpc.common.message.PackageMsg;
import com.bxl.netty.rpc.common.message.RegisterContent;
import com.bxl.netty.rpc.register.server.RegisterServerContext;
import com.bxl.netty.rpc.register.server.ZoneInfos;
import com.bxl.netty.rpc.register.server.service.IOperService;

/**
 * <>
 *
 * @author baixl
 * @date 2021/3/5
 */
public class RegisterService implements IOperService {
    public Object deal(PackageMsg<RegisterContent> msg, RegisterServerContext context) {
        RegisterContent content = msg.getContent();
        ZoneInfos zoneInfos = context.getZoneInfos();
        ClientInfo client = new ClientInfo(content.getApp(),content.getIp(), content.getPort(), null);
        AppInfo zoneInfo = new AppInfo();
        zoneInfo.setApp(content.getApp());
        zoneInfo.addClients(client);
        zoneInfos.addZone(zoneInfo);
        return BaseResponse.success();
    }
}
